package com.tianji.learning.controller;


import com.tianji.api.dto.leanring.LearningLessonDTO;
import com.tianji.common.domain.dto.PageDTO;
import com.tianji.common.domain.query.PageQuery;
import com.tianji.common.utils.UserContext;
import com.tianji.learning.domain.dto.LearningPlanDTO;
import com.tianji.learning.domain.vo.LearningLessonVO;
import com.tianji.learning.domain.vo.LearningPlanPageVO;
import com.tianji.learning.domain.vo.lessonStatusVO;
import com.tianji.learning.service.ILearningLessonService;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 学生课表 前端控制器
 * </p>
 *
 * @author hrz
 * @since 2025-08-28
 */
@RestController
@RequestMapping("/lessons")
@RequiredArgsConstructor
public class LearningLessonController {

    @Autowired
    ILearningLessonService learningLessonService;

    @ApiOperation("分页查询课表的课程")
    @GetMapping("/page")
    public PageDTO<LearningLessonVO> queryLessonPage(@RequestBody PageQuery pageQuery) {
        return learningLessonService.querymyLessons(pageQuery);
    }

    @GetMapping("/now")
    @ApiOperation("查询当前正在学习的课程")
    public LearningLessonVO queryNow() {
        return learningLessonService.queryNowLesson();
    }

    @GetMapping("/{courseId}/valid")
    @ApiOperation("判断课程是否失效")
    public Long isLessonValid(@PathVariable("courseId") Long courseId) {
        return learningLessonService.queryValid(courseId);
    }

    @GetMapping("/{courseId}")
    @ApiOperation("查询当前课程的状态")
    public lessonStatusVO queryById(@PathVariable("courseId") Long courseId) {
        return learningLessonService.queryById(courseId);
    }

    @GetMapping("/{courseId}/count")
    @ApiOperation("查询课程的报名人数")
    Integer countLearningLessonByCourse(@PathVariable("courseId") Long courseId){
        return learningLessonService.countLearningLessonByCourse(courseId);
    }

    @DeleteMapping("/{courseId}")
    @ApiOperation("删除失效课程的记录")
    public void delete(@PathVariable("courseId") Long courseId) {
        learningLessonService.deleteCourse(courseId);
    }

    @PostMapping("/plans")
    @ApiOperation("添加学习计划")
    public void addPlan(@RequestBody LearningPlanDTO d) {
        learningLessonService.addPlan(d.getCourseId(), d.getFreq());
    }

    @GetMapping("/plans")
    @ApiOperation("查询学习计划")
    public LearningPlanPageVO queryPlans(@RequestBody PageQuery pageQuery) {
        return learningLessonService.queryPlans(pageQuery);
    }
}
